package com.czy.esp8266_onenet_control.Onenet;

import com.czy.esp8266_onenet_control.base.BaseRep;
import com.czy.esp8266_onenet_control.javasdk.datastreams.FindDatastreamListApi;
import com.czy.esp8266_onenet_control.javasdk.datastreams.GetDatastreamApi;
import com.czy.esp8266_onenet_control.javasdk.response.BasicResponse;
import com.czy.esp8266_onenet_control.javasdk.response.datastreams.DatastreamsResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.czy.esp8266_onenet_control.base.BaseController.PRODUCT_MASTER_KEY;

/**
 * @Author:ethan
 * @Date: 2023/7/6  10:16
 * @Version 1.0.1
 */
@RestController
@RequestMapping(value = "/datastream")
public class DataStreamController {

    @RequestMapping(value = "/singal")
    public BaseRep dataStreamSingal(String devId, String dataStramId) {

        /**
         * 查询单个数据流
         * @param devid:设备ID,String
         * @param datastreamid:数据流名称 ,String
         * @param key:masterkey 或者 设备apikey
         */
        GetDatastreamApi api = new GetDatastreamApi(devId, dataStramId, PRODUCT_MASTER_KEY);
        BasicResponse<DatastreamsResponse> response = api.executeApi();
//        System.out.println("errno:" + response.errno + " error:" + response.error);
//        System.out.println(response.getData().getId());
        return BaseRep.success(response.getJson());
    }

    @RequestMapping(value = "/multi")
    public BaseRep dataStreamMulti(String devId, String dataStramIds) {

        /**
         * 查询多个数据流
         * @param datastreamids:数据流名称 ,String
         * @param devid:设备ID,String
         * @param key:masterkey 或者 设备apikey
         */
        FindDatastreamListApi api = new FindDatastreamListApi(dataStramIds, devId, PRODUCT_MASTER_KEY);
        BasicResponse<List<DatastreamsResponse>> response = api.executeApi();
//        System.out.println("errno:" + response.errno + " error:" + response.error);
//        System.out.println(response.getJson());
        return BaseRep.success(response.getData());
    }
}
